package demo.services.impl;

import demo.services.IModifyService;
import framework.annotation.InchService;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * implement class for Modify transaction
 */
@InchService
public class ModifyService implements IModifyService {

    @Override
    public String add(String name, String address) {
        return "ModifyService add: name:\t" + name + "\taddress:\t" + address;
    }

    @Override
    public String update(String name, String address) {
        return "ModifyService update: name:\t" + name + "\taddress:\t" + address;
    }

    @Override
    public String remove(String id) throws Exception{
        Matcher matcher = Pattern.compile("\\d+").matcher(id);
        if(matcher.matches()) {
            return "ModifyService remove: ID:\t" + id;
        }else {
            throw new Exception("ModifyService remove failed: ID is not a number");
        }
    }
}
